﻿@model IEnumerable<Masapan_shop.Models.Producto>

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Administracion</h2>

<button class="btn btn-default">
    @Html.ActionLink("Crear nuevo", "Create")
</button>

<button><a href="/MarcaAdm/Create" class="btn btn-default">Crear Marca</a></button>

<input id="campoBusqueda" />
<button onclick="buscar">Buscar</button>

<table class="pure-table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.nombre)
            </th>

            <th>
                @Html.DisplayNameFor(model => model.modelo)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.marca)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.precio)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.descripcion)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.foto)
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>

        @foreach (var item in Model)
        {
            <tr>
                <td>
                    <a href="/Administracion/Details/@item.id">
                        @Html.DisplayFor(modelItem => item.nombre)
                    </a>
                </td>
                <td>
                    @item.modelo
                </td>
                <td>
                    @if (item.marca != null)
                    {
                        <a href="~/MarcaAdm/Details?id=@item.marca.id">@item.marca.nombre</a>
                    }
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.precio)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.descripcion)
                </td>
                <td>
                    <img src=" @Html.DisplayFor(modelItem => item.foto)" width="50px" height="50px" />
                </td>
                <td>
                    <button>@Html.ActionLink("Editar", "Edit", new { id = item.id }) </button>
                    <button>@Html.ActionLink("Detalles", "Details", new { id = item.id }) </button>
                    <button>@Html.ActionLink("Eliminar", "Delete", new { id = item.id })</button>
                </td>


            </tr>
        }
    </tbody>
</table>

@section Scripts
{


    <script>
        $(document).ready(function () {
            $('#buscar').click(function () {
                var areaValue = $('#campoBusqueda').val();
                alert(areaValue);
                $.ajax({
                    url: '/Producto/BuscarMarca/?busqueda=' + areaValue,
                    type: 'get',
                    datatype: 'json'
                }).done(
                    function (data, textStatus, jqXHR) {
                        var object = jQuery.parseJSON(data);
                        return $(document) = object;
                    }
                );
            });
        });
    </script>

}



